package com.lagou.invoker;

import com.lagou.service.MyService;

import java.util.Objects;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;

public class ServiceInvoke implements Runnable {

    private MyService myService;

    public ServiceInvoke(MyService myService) {
        this.myService = myService;
    }

    @Override
    public void run() {
        try {
            TimeUnit.MICROSECONDS.sleep(50);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        String result = null;
        final int i = ThreadLocalRandom.current().nextInt(3);
        switch (i) {
            case 0:
                result = myService.methodA("a");
                break;
            case 1:
                result = myService.methodB("b");
                break;
            case 2:
                result = myService.methodC("c");
                break;
            default:
                break;
        }
        System.out.println(Thread.currentThread().getName() + " result = " + Objects.toString(result, ""));
    }
}
